package com.qf.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.qf.pojo.User;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/search")
public class SearchController {
    @RequestMapping("/test")
    public String test(){

        return "这个search微服务被调用了";
    }

    @RequestMapping("/query/{id}")
    @HystrixCommand(fallbackMethod = "findByIdfallback")
    public User findById(@PathVariable("id") Integer id){
        System.out.println("====id====="+id);
        int i=1/0;
        User user = new User();
        user.setId(1);
        user.setName("大哥");
        user.setBirthday(new Date());
        return user;
    }
    public User findByIdfallback(Integer id){
        User user = new User();
        user.setId(1);
        user.setName("数据出错了");
        return user;
    }
}
